package cn.tedu.boke.portal.service.impl;

import cn.tedu.boke.portal.mapper.*;
import cn.tedu.boke.portal.model.Post;
import cn.tedu.boke.portal.model.User;
import cn.tedu.boke.portal.service.IPostService;
import cn.tedu.boke.portal.vo.PostLabelsVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 帖子 服务实现类
 * </p>
 *
 * @author tedu.cn
 * @since 2021-11-01
 */
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IPostService
{

    @Autowired
    UserMapper userMapper;

    @Autowired
    private PostMapper postMapper;
    @Autowired
    private ViewMapper viewMapper;
    @Autowired
    private LikeMapper likeMapper;
    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public PageInfo<PostLabelsVo> postLabels(Integer pageNum, Integer pageSize)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<PostLabelsVo> posts = postMapper.findAllPosts();
        return new PageInfo<>(posts);
    }

    @Override
    public PostLabelsVo onePost(Integer id)
    {
        PostLabelsVo onePost = postMapper.findOnePost(id);
        return onePost;
    }

    @Override
    //获取当前用户所有帖子
    public List<Post> getMyPoset(String username) {

        User user = userMapper.findUserByUsername(username);

        QueryWrapper<Post> posts = new QueryWrapper<>();
        posts.eq("user_id",user.getId());
        posts.eq("delete_status",0);
        posts.orderByDesc("createtime");

        List<Post> list = postMapper.selectList(posts);


        return list ;
    }
}
